<template>
	<view class="ys">
		<view class="card">
			<car-number-input @numberInputResult="numberInputResult" :defaultStr="defaultNum"></car-number-input>
			<button @click="bind">立即绑定</button>
		</view>
	</view>
</template>

<script>
	import {
		UserCarBind
	} from "@/api/user.js"
	export default {
		data() {
			return {
				defaultNum: '',
				str: ''
			}
		},
		onLoad() {

		},
		methods: {
			numberInputResult(e) {
				this.str = e
			},
			bind() {
				if (this.str.length < 7) {
					uni.$showMsg('请输入正确的车牌号')
				} else if (this.str.length == 7) {
					this.UserCarBind(1)
				} else if (this.str.length == 8) {
					this.UserCarBind(2)
				}
			},
			UserCarBind(car_type) {
				UserCarBind({
					car_number: this.str,
					car_type
				}).then(res => {
					uni.$showMsg(res.message)
					if (res.status == 1) {
						setTimeout(() => {
							uni.navigateBack()
						}, 500)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.ys {
		padding: 10px;
		box-sizing: border-box;
		background: #fafafa;
		min-height: 100vh;
		/* #ifdef H5 */
		min-height: calc(100vh - 44px);
		/* #endif */
		height: 100%;
		padding-top: 20px;

		.card {
			background: #fff;
			width: 100%;
			margin: 0 auto;
			border-radius: 10px;
			padding: 20px 10px;
			box-sizing: border-box;
		}
	}

	button {
		width: 96%;
		margin: 0px auto;
		margin-top: 20px;
		background: #55aaff;
		font-size: 14px;
		color: #fff;
	}
</style>